<template>
    <div>
        <page-header title="元数据" />
        <page-main>
            <el-card class="box-card">
                <el-button class="pull-right" type="primary" size="small" icon="el-icon-plus" @click="dialogVisible = true">新增元数据</el-button>
                <hr>
                <el-table :data="tableData" border style="width: 100%;">
                    <el-table-column label="序号" type="index" align="center" show-overflow-tooltip width="50px">
                    </el-table-column>
                    <el-table-column label="名称" prop="name">
                    </el-table-column>
                    <el-table-column prop="source" label="来源">
                        <template slot-scope="scope">
                            <el-tag :type="scope.row.source === 0 ? 'primary' : 'success'" disable-transitions>{{scope.row.source === 0 ? '用户创建' : '自动生成'}}</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column prop="comment" width="180" label="备注" show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column label="操作">
                        <template slot-scope="scope">
                            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                            <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination
                    :current-page.sync="currentPage"
                    :page-size="100"
                    :total="1000"
                    layout="total, prev, pager, next"
                    @current-change="handleCurrentChange"
                    @size-change="handleSizeChange">
                </el-pagination>
            </el-card>
        </page-main>
        <el-dialog
            :title="title"
            :visible.sync="dialogVisible"
            width="30%"
            :before-close="handleClose">

            <el-form ref="form" :model="metaForm" size="small" label-width="80px">
                <el-form-item label="名称">
                    <el-input v-model="metaForm.name"></el-input>
                </el-form-item>
                <el-form-item label="备注">
                    <el-input type="textarea" :rows="2" v-model="metaForm.comment" />
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button size="small" @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" size="small" @click="dialogVisible = false">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
    name: 'MetaDataPage',
    data() {
        return {
            title: '新增',
            dialogVisible: false,
            currentPage: 1,
            tableData: [{
                date: '2021-05-02',
                name: '王小虎',
                source: 0,
                comment: '这是一个备注'
            }, {
                date: '2021-05-04',
                name: '王二虎',
                source: 1,
                comment: '这是一个备注'
            }, {
                date: '2021-05-01',
                name: '王三虎',
                source: 0,
                comment: '这是一个备注'
            }, {
                date: '2021-05-03',
                name: '王四虎',
                source: 0,
                comment: '这是一个备注'
            }],
            metaForm: {}
        }
    },
    methods: {
        handleClose(done) {
            // this.$confirm('确认关闭？')
            done()
        },
        handleEdit(index, row) {
            console.log(index, row)
        },
        handleDelete(index, row) {
            console.log(index, row)
        },
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`)
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`)
        }
    }
}
</script>

<style>
.text {
    font-size: 14px;
}
.item {
    margin-bottom: 18px;
}
.clearfix::before,
.clearfix::after {
    display: table;
    content: "";
}
.clearfix::after {
    clear: both;
}
.box-card {
    width: 100%;
}
</style>

